# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Contributor: Ionut Biru <ibiru@archlinux.org>
# Contributor: Hugo Doria <hugo@archlinux.org>

pkgname=libtorrent-rasterbar
pkgver=2.0.9
pkgrel=3
epoch=1
pkgdesc="A C++ BitTorrent library that aims to be a good alternative to all the other implementations around"
url="https://www.rasterbar.com/products/libtorrent/"
arch=('loong64' 'x86_64')
license=('BSD')
depends=('boost-libs' 'openssl')
makedepends=('boost' 'cmake' 'ninja' 'python-setuptools')
options=('!emptydirs')
source=(https://github.com/arvidn/libtorrent/releases/download/v$pkgver/$pkgname-$pkgver.tar.gz
        fortify-source-3.patch)
sha512sums=('c252dbe1e2a246769017b8a622bb3418527e2bc2615115ac2bff9662afb53759bc7b2cbf6657438c515ba6de0140fc1c388b340c48b3dd9f7e6202ec0df1aec7'
            '0687883a84f4395afaa824f5a2a9ee5366d654d84f546045b202297084ff24c445e4b95e92df63a8d9d2cd28cbd665933f3c649de91ab13334507f7a7d2c3c5d')

prepare() {
  # remove usage of malloc_usable_size for _FORTIFY_SOURCE=3 compatibility
  # https://github.com/arvidn/libtorrent/issues/7519
  cd $pkgname-$pkgver
  patch -Np1 -i ../fortify-source-3.patch
}

build() {
  cmake -B build -S $pkgname-$pkgver \
    -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_INSTALL_PREFIX="/usr" \
    -DCMAKE_INSTALL_LIBDIR="lib" \
    -Dpython-bindings=ON \
    -Dboost-python-module-name="python" \
    -Dpython-egg-info=ON \
    -Wno-dev
  cmake --build build
}

package() {
  DESTDIR="$pkgdir" cmake --install build
  install -Dm644 $pkgname-$pkgver/COPYING -t "$pkgdir"/usr/share/licenses/$pkgname/
}
